/*
 * Copyright (c) csii.com.cn 2016 zhaojin
 */

package com.csii.ssm.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.Locale;

/**
 * Created by zhaojin on 16/2/22.
 */
@Component("springContextUtil")
@Scope("singleton")
public class SpringContextUtil implements ApplicationContextAware {

    public static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public static Object getBean(String beanName){
        return applicationContext.getBean(beanName);
    }

    public static String getMessage(String key){
        return applicationContext.getMessage(key, null, Locale.getDefault());
    }

    public static String getMessage(String key, Object[] args){
        return applicationContext.getMessage(key, args, Locale.getDefault());
    }

    public static String getMessage(String key, Locale locale){
        return applicationContext.getMessage(key, null,locale);
    }
}
